package com.zh.search.dataSource;

import cn.hutool.core.bean.BeanUtil;
import com.zh.search.domain.dto.ArticleSearchDto;
import com.zh.search.domain.dto.SearchDto;
import com.zh.search.service.IEsService;
import com.zh.web.base.PageApiResult;
import com.zh.web.domain.media.vo.ArticleVo;
import org.springframework.stereotype.Component;

@Component
public class ArticleEsDataSource implements EsDataSource<ArticleVo> {

    private final IEsService esService;

    public ArticleEsDataSource(IEsService esService) {
        this.esService = esService;
    }

    @Override
    public PageApiResult<ArticleVo> doSearch(SearchDto searchDto) {
        ArticleSearchDto articleSearchDto = new ArticleSearchDto();
        BeanUtil.copyProperties(searchDto, articleSearchDto);
        PageApiResult<ArticleVo> articleVoPageApiResult = esService.searchArticleFromEs(articleSearchDto);
        return articleVoPageApiResult;
    }

}
